home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1998 January
/
Macworld (1998-01).dmg
/
Shareware World
/
Comms & Internet
/
HTML mode 2.0 etc.
/
javaScriptMode.tcl
< prev
next >
Wrap
Text File
|
1997-09-22
|
4KB
|
151 lines
## -*-Tcl-*-
# ###################################################################
# JavaScript mode - tools for editing JavaScript documents
#
# FILE: "javaScriptMode.tcl"
# created: 97-02-09 14.00.54
# last update: 97-09-16 19.01.56
# Author: Johan Linde
# E-mail: <jl@theophys.kth.se>
# www: <http://bach.theophys.kth.se/~jl/Alpha.html>
#
# Version: 1.0.2
#
# Copyright 1997 by Johan Linde
#
# This software may be used freely, and distributed freely, as long as the
# receiver is not obligated in any way by receiving it.
#
# If you make improvements to this file, please share them!
#
# ###################################################################
##
if {$startingUp} {
addMode JScr JScrDummy {*.js *.JS} {}
return
}
# ◊◊◊◊ Change below for new system §12 ◊◊◊◊ #
newModeVar JScr elecRBrace 1 1
newModeVar JScr prefixString {//} 0
newModeVar JScr elecLBrace 1 1
newModeVar JScr electricSemi 1 1
newModeVar JScr wordWrap 0 1
newModeVar JScr funcExpr {^function *([+-a-zA-Z0-9]+)} 0
newModeVar JScr parseExpr {^function *([+-a-zA-Z0-9]+)} 0
newModeVar JScr wordBreak {\w+} 0
newModeVar JScr wordBreakPreface {\W} 0
newModeVar JScr electricTab 0 1
newModeVar JScr stringColor green 0
newModeVar JScr commentColor red 0
newModeVar JScr keywordColor blue 0
# ◊◊◊◊ end changing for new system §12 ◊◊◊◊ #
regModeKeywords -e {//} -b {/*} {*/} -c $JScrmodeVars(commentColor) -k $JScrmodeVars(keywordColor) -s $JScrmodeVars(stringColor) JScr {
break case continue default do for in function if else new return switch this var while with true false }
proc JScrDummy {} {}
# ◊◊◊◊ Change below for new system §13 ◊◊◊◊ #
proc JScrindentLine {} { CindentLine }
bind 'l' <C> cDividingLine JScr
if {[info commands useUniversalCompletions] == ""} {
# No Vince's Additions
newModeVar JScr elecColon 1 1
bind '\{' <s> electricLeft JScr
bind '\}' <s> electricRight JScr
bind '\;' JScrelectricSemi JScr
bind '\t' doATab JScr
bind '\t' <o> {doATab 1} JScr
bind '\r' JScrCarriageReturn JScr
# Carriage return
# Identical with the C/C++ proc, but I want it to be independent of C/C++ mode.
proc JScrCarriageReturn {} {
if {[lookAt [expr [getPos] - 1]] == ":"} {
if { [lookAt [getPos]] == "\r" } {
indentLine
endOfLine
carriageReturn
} else {
set pos [getPos]
endOfLine
set t [getText $pos [getPos]]
replaceText $pos [getPos] ""
indentLine
endOfLine
carriageReturn
insertText $t
}
indentLine
} else {
carriageReturn
indentLine
}
}
# Electric semicolon
# Identical with the original proc, but I want it to be independent of C/C++ mode.
proc JScrelectricSemi {} {
global JScrmodeVars
if [isSelection] { deleteSelection }
if {!$JScrmodeVars(electricSemi)} {
insertText ";"
return
}
set pos [getPos]
set start [lineStart $pos]
set text [getText $start $pos]
if {[string first "for" $text] != "-1"} {
set lefts 0
set rights 0
set len [string length $text]
for {set i 0} {$i < $len} {incr i} {
case [string index $text $i] in {
"(" { incr lefts }
")" { incr rights }
}
}
if {$lefts != $rights} {
insertText ";"
return
}
}
insertText ";\r" [JScrGetIndent $pos]
}
# get the leading whitespace of the current line
proc JScrGetIndent { pos } {
set res [search -s -n -f 1 -r 1 "^\[ \t\]*" [lineStart $pos]]
return [JScrIndentConvert [eval getText $res]]
}
# convert it to minimal form: tabs then spaces.
proc JScrIndentConvert {indent} {
getWinInfo a
set sp [string range " " 1 $a(tabsize) ]
regsub -all $sp $indent "\t" indent
regsub -all "\[ \]+\t" $indent "\t" indent
return $indent
}
} else {
# Vince's Additions
newModeVar JScr electricColon 1 1
set commentCharacters(JScr:General) [list "*" "//"]
set commentCharacters(JScr:Paragraph) [list "/* " " */" " * "]
set commentCharacters(JScr:Box) [list "/*" 2 "*/" 2 "*" 3]
proc JScrcarriageReturn {} {C++carriageReturn}
}
# ◊◊◊◊ end changing for new system §13 ◊◊◊◊ #